﻿using System;
using System.IO;
using System.Net;

namespace Jok.Client.Loader
{
    /// <summary>
    /// event classes
    /// </summary>
    public class DownloadProgressEventArgs : EventArgs
    {
        public DownloadProgressEventArgs()
        {

        }

        public DownloadProgressEventArgs(DownloadProgressChangedEventArgs e)
        {
            BytesReceived = e.BytesReceived;
            TotalBytesToReceive = e.TotalBytesToReceive;
        }
        // Summary:
        //     Gets the number of bytes received.
        //
        // Returns:
        //     An System.Int64 value that indicates the number of bytes received.
        public long BytesReceived { get; set; }
        //
        // Summary:
        //     Gets the total number of bytes in a System.Net.WebClient data download operation.
        //
        // Returns:
        //     An System.Int64 value that indicates the number of bytes that will be received.
        public long TotalBytesToReceive { get; set; }
        // Summary:
        //     Gets the percentage of an asynchronous operation that has been completed.
        //
        // Returns:
        //     A percentage value that indicates the asynchronous operation progress.
        public int ProgressPercentage
        {
            get
            {
                return (int)Math.Round(((double)BytesReceived / TotalBytesToReceive) * 100);
            }
        }
    }

    public class DownloadCompleteEventArgs : EventArgs
    {
        public DownloadCompleteEventArgs()
        {

        }

        public DownloadCompleteEventArgs(OpenReadCompletedEventArgs e)
        {
            Cancelled = e.Cancelled;
            Error = e.Error;
            if (e.Error == null)
            {
                Result = e.Result;
            }
            else
                Result = null;
        }
        // Summary:
        //     Gets a readable stream that contains the results of the System.Net.WebClient.OpenReadAsync(System.Uri,System.Object)
        //     method.
        //
        // Returns:
        //     A System.IO.Stream that contains the results of the System.Net.WebClient.OpenReadAsync(System.Uri,System.Object)
        //     method.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     The asynchronous request was cancelled.
        public Stream Result { get; set; }
        // Summary:
        //     Gets a value that indicates whether an asynchronous operation has been canceled.
        //
        // Returns:
        //     true if the asynchronous operation has been canceled; otherwise, false. The
        //     default is false.
        public bool Cancelled { get; set; }
        //
        // Summary:
        //     Gets a value that indicates which error occurred during an asynchronous operation.
        //
        // Returns:
        //     An System.Exception instance, if an error occurred during an asynchronous
        //     operation; otherwise null.
        public Exception Error { get; set; }
    }
}
